package com.endava.exceptions.handling;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * The order for hierarchical exceptions matters. IOException is the superclass
 * for FileNotFoundException.
 * 
 * @author Andreea
 * 
 */
public class ReadData {
	public static void main(String args[]) {
		try {
			System.out.println("Entering the try block.");
			RandomAccessFile raf = new RandomAccessFile("myfile.txt", "r");
			System.out.println("Found the file.");
			byte b[] = new byte[1000];
			raf.readFully(b, 0, 1000);
			System.out.println("Finished the try block.");
			
		} catch (FileNotFoundException e) {
			System.err.println("File not found");
			System.err.println("Message:"+e.getMessage()); 	//to print the error message
			System.err.println("Stack trace:");
			e.printStackTrace();							//to print the error stack trace
			
		} catch (IOException e) {
			System.err.println("IO Error");
			System.err.println(e.toString()); 				//printing the exception and a message
			System.err.println("Stack trace:");
			e.printStackTrace();
		}
	}
}